//
//  CRHook.m
//  crashreport
//
//  Created by william on 12-8-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CRHook.h"
#import <objc/runtime.h>

@implementation CRHook

+(void) exchangeClassMethod:(SEL) srcMethod inSrcClass:(Class) srcClass withMethod:(SEL) dstMethod inDstClass:(Class) dstClass
{
    Method old = class_getClassMethod(srcClass, srcMethod);
    NSAssert(old != NULL, @"src method does not exist!");
    
    Method new = class_getClassMethod(dstClass, dstMethod);
    NSAssert(new != NULL, @"dst method does not exist!");
    
    method_exchangeImplementations(old, new);
}

+(void) exchangeInstanceMethod:(SEL) srcMethod inSrcClass:(Class) srcClass withMethod:(SEL) dstMethod inDstClass:(Class) dstClass
{
    Method old = class_getClassMethod(srcClass, srcMethod);
    NSAssert(old != NULL, @"src method does not exist!");
    
    Method new = class_getInstanceMethod(dstClass, dstMethod);
    NSAssert(new != NULL, @"dst method does not exist!");
    
    method_exchangeImplementations(old, new);
}

@end
